﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using CustomsSystem.BLL;
using CustomsSystem.Model;

namespace WEB.Emp
{
    public partial class AddEmp : System.Web.UI.Page
    {
        DataSet ds;
        EmpManage BLL = new EmpManage();
        Info_emp empMo = new Info_emp();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                JobManage job = new JobManage();
                DropDownList1.DataSource = job.GetAllList();
                DropDownList1.DataTextField = "jobname";
                DropDownList1.DataValueField = "JobNo";
                DropDownList1.DataBind();

                if (Request.QueryString["jobno"] != "")
                {
                    string emptype = Convert.ToString(Request.QueryString["jobno"]);
                    DropDownList1.Text = emptype;
                }
            }
            Label5.Text = DropDownList1.Text;
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            string empNum = TextBox1.Text;
            bool a;
            a = BLL.Exists(empNum);

            if (TextBox1.Text.Trim() == "" || TextBox2.Text.Trim() == "" || TextBox3.Text == "" || TextBox4.Text == "")
            {
                Response.Write("<Script>alert('请输入完整!')</script>");
            }
            else
            {
                if (a == false)
                {
                    if (TextBox4.Text == TextBox3.Text)
                    {
                        empMo.JobNo = Label5.Text;
                        empMo.EmpNum = TextBox1.Text;
                        empMo.UserName = TextBox2.Text;
                        empMo.PassWord = stringpro .md5 (TextBox3.Text);
                        empMo.Remarks = TextBox5.Text;
                        BLL.Add(empMo);
                        TextBox1.Text = string.Empty;
                        TextBox2.Text = string.Empty;
                        TextBox3.Text = string.Empty;
                        TextBox4.Text = string.Empty;
                        TextBox5.Text = string.Empty;
                        Label8.Text = string.Empty;
                        Response.Write("<Script>alert('增加成功!')</script>");
                    }
                    else
                    {
                        Response.Write("<Script>alert('输入的俩次密码不一致,请重新输入!')</script>");
                    }
                }
                else
                {
                    Response.Write("<Script>alert('该工号已有,请重新输入!')</script>");
                }
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {

            string emptype = Convert.ToString(Request.QueryString["jobno"]);
            Response.Redirect("EmpIndex.aspx?jobno="+emptype);
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text.Trim() != "")
            {
                string empNum = TextBox1.Text;
                bool a;
                a = BLL.Exists(empNum);
                if (a == true)
                {
                    Label8.Text = " 该工号已有,请重新输入!";
                }
                else
                {
                    Label8.Text = " 恭喜，可以使用该工号";
                }
            }
            else
            {
                Label8.Text = "请输入工号!";
            }
        }

        protected void Label8_DataBinding(object sender, EventArgs e)
        {
            string empNum = TextBox1.Text;
            bool a;
            a = BLL.Exists(empNum);
            if (a == true)
            {
                Response.Write("<Script>alert('该工号已有,请重新输入!')</script>");
            }
            else
            {
                Response.Write("<Script>alert('该工号还没有，可以使用!')</script>");
            }
        }
    }
}